from .base import Base, db


class Role(Base):

    __tablename__ = 'roles'

    code = db.Column(db.String(10), nullable=False)
    name = db.Column(db.String(50), nullable=False)
    enabled = db.Column(db.String(1), nullable=False)
    is_global = db.Column(db.String(1), nullable=False)
    description = db.Column(db.String(150))

    def __init__(self, code, org_code, name, description, create_user, update_user):
        super(Role, self).__init__(create_user, update_user)
        self.code = code
        self.org_code = org_code
        self.name = name
        self.description = description

    def __repr__(self):
        desc = 'Role:{'
        for key in self.__dict__:
            desc += '%s:%s\n' % (key, self.__dict__[key])
        return desc % '}'
